//
// Resource.h
// Usage: Resource object define
// Create Date: 2009-03-05
// Author: MaJiuyue
//
#ifndef _RESOURCE_H_
#define _RESOURCE_H_

#include "type.h"
#include "Map.h"

/* Resource callable interface */
class Callable
{
public:
	Callable() {};
	virtual ~Callable() {};
};

/* Resource Object */
class Resource
{
public:
	typedef int (Callable::*CallInterface0)();
	typedef int (Callable::*CallInterface1)(int);
	typedef int (Callable::*CallInterface2)(int,int);
	typedef int (Callable::*CallInterface3)(int,int,int);
	typedef int (Callable::*CallInterface4)(int,int,int,int);
	typedef int (Callable::*CallInterface5)(int,int,int,int,int);

public:
	/* Construct resource */
	Resource(Callable * target);
	/* Destory resource */
	~Resource();

	void SetResourceID(int iResourceID)  { m_iResourceID = iResourceID; }
	u32 GetResourceID()  { return m_iResourceID; }

public:
	/*
	    Usage: Register a service interface 
	    Parameters:
	        SCI	-	Service call interface
	        SCIID	-	Service call interface ID
	*/
	bool RegisterInterface(CallInterface0 SCI, u32 SCIID);
	bool RegisterInterface(CallInterface1 SCI, u32 SCIID);
	bool RegisterInterface(CallInterface2 SCI, u32 SCIID);
	bool RegisterInterface(CallInterface3 SCI, u32 SCIID);
	bool RegisterInterface(CallInterface4 SCI, u32 SCIID);
	bool RegisterInterface(CallInterface5 SCI, u32 SCIID);

	/*
	    Usage: Remove a service interface
	    Parameters:
	        SCIID	-	Service call interface ID
	*/
	void RemoveInterface(u32 SCIID);

	virtual u32 CallSCI(u32 SCIID, u32 p1=0, u32 p2=0, u32 p3=0, u32 p4=0, u32 p5=0);

private:
	/* Resource ID allocated by ResourceManager */
	int m_iResourceID;
	
	/* Resource service call target */
	Callable * m_target;

	/* Service Interface Map */
	Map<u32, CallInterface0, 5> SCIT0;
	Map<u32, CallInterface1, 5> SCIT1;
	Map<u32, CallInterface2, 5> SCIT2;
	Map<u32, CallInterface3, 5> SCIT3;
	Map<u32, CallInterface4, 5> SCIT4;
	Map<u32, CallInterface5, 5> SCIT5;
};

#endif
